package rexsee.core.browser.clazz;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

public class ActivityResult {
	private int mRequestCode = 0;
	private ActivityResultListener mListener = null;
	private final Context mContext;
	public ActivityResult(Context context) {
		mContext = context;
	}
	public void start(Intent startIntent, ActivityResultListener listener) {
		mRequestCode++;
		mListener = listener;
		((Activity) mContext).startActivityForResult(startIntent, mRequestCode);
	}
	public void run(int requestCode, int resultCode, Intent resultIntent) {
		if (requestCode == mRequestCode && mListener != null) {
			ActivityResultListener listener = mListener;
			mListener = null;
			listener.run(resultCode, resultIntent);
		}
	}
	public static abstract class ActivityResultListener {
		public abstract void run(int resultCode, Intent resultIntent);
	}
}
